var config = {
    serverHost: 'http://localhost:8888/'
};

var _util = {
    request: function(param){
        var _this = this;
        $.ajax({
            type: param.method || 'GET',
            url: param.url || '',
            dataType: param.type || 'json',
            data: param.data || '',
            success:function(res){
                if(0==res.status){
                    typeof param.success === 'function' && param.success(res.data,res.msg);
                }else if(10==res.status){
                    _this.doLogin();
                }else if(1==res.status){
                    typeof param.error === 'function' && param.error(res.msg);
                }
            },
            error: function(errMsg){
                //请求错误的提示
            }
        });
    },
    doLogin: function(){
        window.location.href = './account-login.html?redirect='+encodeURIComponent(window.location.href);
    },
    getServerURL: function(path){
        return config.serverHost + path;
    }
};

module.exports = _util;